package com.ali.ttt.netty.common.utils;

import com.alibaba.fastjson.JSONObject;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

import java.nio.charset.StandardCharsets;

/**
 * @author yuxl
 */
public class MessageUtil {

    public static void send(ChannelHandlerContext ctx, Object msg){
        Channel channel = ctx.channel();
        channel.writeAndFlush(Unpooled.copiedBuffer(JSONObject.toJSONString(msg), StandardCharsets.UTF_8));
    }

    public static void send(Channel channel, Object msg){
        channel.writeAndFlush(Unpooled.copiedBuffer(JSONObject.toJSONString(msg), StandardCharsets.UTF_8));
    }
}
